package controllers

import (
	"ktvserver/ktvutil"
	"log"
)

type DdnsController struct {
	UserController
}

// 显示动态域名信息
func (c *DdnsController) Get() {
	c.TplNames = "ddns"
	c.Data["title"] = "动态域名"

	ddns_name, ddns_key, isEnable := ktvutil.GetDDnsParam()

	c.Data["ddns_name"] = ddns_name
	c.Data["ddns_key"] = ddns_key

	if isEnable {
		c.Data["ddns_enable"] = 1
	} else {
		c.Data["ddns_enable"] = 0
	}
}

// 修改动态域名信息
func (c *DdnsController) Post() {
	c.TplNames = "ddns"
	c.Data["title"] = "动态域名"

	ddns_name := c.GetString("ddns_name")
	ddns_key := c.GetString("ddns_key")
	ddns_enable := c.GetString("ddns_enable")

	isEnable := true

	log.Printf("ddns_name=%s, ddns_key=%s, ddns_enable=%v", ddns_name, ddns_key, ddns_enable)

	if ddns_enable == "on" {
		c.Data["ddns_enable"] = 1
		isEnable = true
	} else {
		c.Data["ddns_enable"] = 0
		isEnable = false
	}

	// 保存设置
	ktvutil.SetDDnsParam(ddns_name, ddns_key, isEnable)

	c.Data["ddns_name"] = ddns_name
	c.Data["ddns_key"] = ddns_key
	c.Data["saveok"] = 1

}
